package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.mapper.MemberMapper;
import com.itheima.mapper.OrderMapper;
import com.itheima.mapper.SetmealMapper;
import com.itheima.pojo.Setmeal;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberMapper memberMapper;
    @Autowired
    private OrderMapper orderMapper;


    //获取
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        Map<String, Object> resultMap =  new HashMap<String, Object>();
        //获取当日日期--报表日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取周一日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取当月第一天
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //报表当日日期
        resultMap.put("reportDate",today );
        //当日新增会员数
        Integer todayNewMember = memberMapper.findMemberCountByDate(today);
        resultMap.put("todayNewMember",todayNewMember);
        //总会员数
        Integer totalMember = memberMapper.findMemberTotalCount();
        resultMap.put("totalMember",totalMember);
        //本周新增会员数
        Integer thisWeekNewMember = memberMapper.findMemberCountAfterDate(thisWeekMonday);
        resultMap.put("thisWeekNewMember",thisWeekNewMember);
        //本月新增会员
        Integer thisMonthNewMember = memberMapper.findMemberCountAfterDate(firstDay4ThisMonth);
        resultMap.put("thisMonthNewMember",thisMonthNewMember);

        //统计今日预约数
        Integer todayOrderNumber = orderMapper.findOrderCountByDate(today);
        resultMap.put("todayOrderNumber",todayOrderNumber);

        //本周预约数
        Integer thisWeekOrderNumber = orderMapper.findOrderCountAfterDate(thisWeekMonday);
        resultMap.put("thisWeekOrderNumber",thisWeekOrderNumber);
        //本月预约数
        Integer thisMonthOrderNumber = orderMapper.findOrderCountAfterDate(firstDay4ThisMonth);
        resultMap.put("thisMonthOrderNumber",thisMonthOrderNumber);

        //今日到诊数
        Integer todayVisitsNumber = orderMapper.findVisitsCountByDate(today);
        resultMap.put("todayVisitsNumber",todayVisitsNumber);
        //本周到诊数
        Integer thisWeekVisitsNumber = orderMapper.findVisitsCountAfterDate(thisWeekMonday);
        resultMap.put("thisWeekVisitsNumber",thisWeekVisitsNumber);

        //本月到诊数
        Integer thisMonthVisitsNumber = orderMapper.findVisitsCountAfterDate(firstDay4ThisMonth);
        resultMap.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

        //热门套餐查询
        List<Map<String, Object>> hotSetmeal = orderMapper.findHotSetmeal();
        resultMap.put("hotSetmeal",hotSetmeal);
        return resultMap;
    }
}
